﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IsmsExplorer.IsmsDataImport.UI.Common;
using IsmsExplorer.Model.Projects;
using IsmsExplorer.Application.Projects;

namespace IsmsExplorer.IsmsDataImport.UI {
    public partial class NewProjectForm : Form {
        private Project _project;
        public Project Project {
            get { return _project; }
            set { _project = value; }
        }

        public NewProjectForm() {
            InitializeComponent();
        }

        private void NewProjectForm_Load(object sender, EventArgs e) {
            txtProjectName.Text = "New Project";
            dateTime1.Value = DateTime.Today;
        }

        private void btnCreate_Click(object sender, EventArgs e) {
            try {
                Cursor = Cursors.WaitCursor;
                Project p = new Project(txtProjectName.Text) {
                    StartDate = dateTime1.Value
                };
                ProjectService.SaveProject(p);
                this.Project = p;

                this.DialogResult = System.Windows.Forms.DialogResult.OK;

            } catch (Exception ex) {
                UIHelper.ShowErrorMessage(this, ex.Message);
             
            } finally {
                Cursor = Cursors.Default;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e) {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
        }
    }
}
